.class public Lcom/zuiapps/sdk/analytics/db/DatabaseOpenHelper;
.super Lcom/zuiapps/sdk/analytics/greendao/DaoMaster$OpenHelper;
.source "DatabaseOpenHelper.java"


# static fields
.field public static final MIGRATION_PATH:Ljava/lang/String; = "analyticsmigrations"


# instance fields
.field private mContext:Landroid/content/Context;


# direct methods
.method public constructor <init>(Landroid/content/Context;Ljava/lang/String;Landroid/database/sqlite/SQLiteDatabase$CursorFactory;)V
    .registers 4
    .param p1, "context"    # Landroid/content/Context;
    .param p2, "name"    # Ljava/lang/String;
    .param p3, "factory"    # Landroid/database/sqlite/SQLiteDatabase$CursorFactory;

    .prologue
    .line 32
    invoke-direct {p0, p1, p2, p3}, Lcom/zuiapps/sdk/analytics/greendao/DaoMaster$OpenHelper;-><init>(Landroid/content/Context;Ljava/lang/String;Landroid/database/sqlite/SQLiteDatabase$CursorFactory;)V

    .line 33
    iput-object p1, p0, Lcom/zuiapps/sdk/analytics/db/DatabaseOpenHelper;->mContext:Landroid/content/Context;

    .line 34
    return-void
.end method

.method public static closeQuietly(Landroid/database/Cursor;)V
    .registers 2
    .param p0, "cursor"    # Landroid/database/Cursor;

    .prologue
    .line 135
    if-nez p0, :cond_3

    .line 143
    :goto_2
    return-void

    .line 140
    :cond_3
    :try_start_3
    invoke-interface {p0}, Landroid/database/Cursor;->close()V
    :try_end_6
    .catch Ljava/lang/Exception; {:try_start_3 .. :try_end_6} :catch_7

    goto :goto_2

    .line 141
    :catch_7
    move-exception v0

    goto :goto_2
.end method

.method public static closeQuietly(Ljava/io/Closeable;)V
    .registers 2
    .param p0, "closeable"    # Ljava/io/Closeable;

    .prologue
    .line 115
    if-nez p0, :cond_3

    .line 123
    :goto_2
    return-void

    .line 120
    :cond_3
    :try_start_3
    invoke-interface {p0}, Ljava/io/Closeable;->close()V
    :try_end_6
    .catch Ljava/io/IOException; {:try_start_3 .. :try_end_6} :catch_7

    goto :goto_2

    .line 121
    :catch_7
    move-exception v0

    goto :goto_2
.end method

.method private executeLegacySqlScript(Landroid/database/sqlite/SQLiteDatabase;Ljava/io/InputStream;)V
    .registers 11
    .param p1, "db"    # Landroid/database/sqlite/SQLiteDatabase;
    .param p2, "stream"    # Ljava/io/InputStream;
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    .line 93
    const/4 v3, 0x0

    .line 94
    .local v3, "reader":Ljava/io/InputStreamReader;
    const/4 v0, 0x0

    .line 96
    .local v0, "buffer":Ljava/io/BufferedReader;
    :try_start_2
    new-instance v4, Ljava/io/InputStreamReader;

    invoke-direct {v4, p2}, Ljava/io/InputStreamReader;-><init>(Ljava/io/InputStream;)V
    :try_end_7
    .catchall {:try_start_2 .. :try_end_7} :catchall_52

    .line 97
    .end local v3    # "reader":Ljava/io/InputStreamReader;
    .local v4, "reader":Ljava/io/InputStreamReader;
    :try_start_7
    new-instance v1, Ljava/io/BufferedReader;

    invoke-direct {v1, v4}, Ljava/io/BufferedReader;-><init>(Ljava/io/Reader;)V
    :try_end_c
    .catchall {:try_start_7 .. :try_end_c} :catchall_54

    .line 98
    .end local v0    # "buffer":Ljava/io/BufferedReader;
    .local v1, "buffer":Ljava/io/BufferedReader;
    const/4 v2, 0x0

    .line 100
    .local v2, "line":Ljava/lang/String;
    :cond_d
    :goto_d
    :try_start_d
    invoke-virtual {v1}, Ljava/io/BufferedReader;->readLine()Ljava/lang/String;

    move-result-object v2

    if-eqz v2, :cond_4b

    .line 101
    const-string v5, ";"

    const-string v6, ""

    invoke-virtual {v2, v5, v6}, Ljava/lang/String;->replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;

    move-result-object v5

    invoke-virtual {v5}, Ljava/lang/String;->trim()Ljava/lang/String;

    move-result-object v2

    .line 102
    invoke-static {v2}, Landroid/text/TextUtils;->isEmpty(Ljava/lang/CharSequence;)Z

    move-result v5

    if-nez v5, :cond_d

    .line 103
    const-string v5, ""

    new-instance v6, Ljava/lang/StringBuilder;

    invoke-direct {v6}, Ljava/lang/StringBuilder;-><init>()V

    const-string v7, "analyticsmigrations line="

    invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v6

    invoke-static {v5, v6}, Lcom/zuiapps/sdk/analytics/util/ZMLogUtil;->e(Ljava/lang/String;Ljava/lang/String;)V

    .line 104
    invoke-virtual {p1, v2}, Landroid/database/sqlite/SQLiteDatabase;->execSQL(Ljava/lang/String;)V
    :try_end_40
    .catchall {:try_start_d .. :try_end_40} :catchall_41

    goto :goto_d

    .line 108
    :catchall_41
    move-exception v5

    move-object v0, v1

    .end local v1    # "buffer":Ljava/io/BufferedReader;
    .restart local v0    # "buffer":Ljava/io/BufferedReader;
    move-object v3, v4

    .end local v2    # "line":Ljava/lang/String;
    .end local v4    # "reader":Ljava/io/InputStreamReader;
    .restart local v3    # "reader":Ljava/io/InputStreamReader;
    :goto_44
    invoke-static {v0}, Lcom/zuiapps/sdk/analytics/db/DatabaseOpenHelper;->closeQuietly(Ljava/io/Closeable;)V

    .line 109
    invoke-static {v3}, Lcom/zuiapps/sdk/analytics/db/DatabaseOpenHelper;->closeQuietly(Ljava/io/Closeable;)V

    throw v5

    .line 108
    .end local v0    # "buffer":Ljava/io/BufferedReader;
    .end local v3    # "reader":Ljava/io/InputStreamReader;
    .restart local v1    # "buffer":Ljava/io/BufferedReader;
    .restart local v2    # "line":Ljava/lang/String;
    .restart local v4    # "reader":Ljava/io/InputStreamReader;
    :cond_4b
    invoke-static {v1}, Lcom/zuiapps/sdk/analytics/db/DatabaseOpenHelper;->closeQuietly(Ljava/io/Closeable;)V

    .line 109
    invoke-static {v4}, Lcom/zuiapps/sdk/analytics/db/DatabaseOpenHelper;->closeQuietly(Ljava/io/Closeable;)V

    .line 111
    return-void

    .line 108
    .end local v1    # "buffer":Ljava/io/BufferedReader;
    .end local v2    # "line":Ljava/lang/String;
    .end local v4    # "reader":Ljava/io/InputStreamReader;
    .restart local v0    # "buffer":Ljava/io/BufferedReader;
    .restart local v3    # "reader":Ljava/io/InputStreamReader;
    :catchall_52
    move-exception v5

    goto :goto_44

    .end local v3    # "reader":Ljava/io/InputStreamReader;
    .restart local v4    # "reader":Ljava/io/InputStreamReader;
    :catchall_54
    move-exception v5

    move-object v3, v4

    .end local v4    # "reader":Ljava/io/InputStreamReader;
    .restart local v3    # "reader":Ljava/io/InputStreamReader;
    goto :goto_44
.end method

.method private executeMigrations(Landroid/database/sqlite/SQLiteDatabase;II)Z
    .registers 13
    .param p1, "db"    # Landroid/database/sqlite/SQLiteDatabase;
    .param p2, "oldVersion"    # I
    .param p3, "newVersion"    # I

    .prologue
    .line 48
    const/4 v3, 0x0

    .line 50
    .local v3, "migrationExecuted":Z
    :try_start_1
    iget-object v5, p0, Lcom/zuiapps/sdk/analytics/db/DatabaseOpenHelper;->mContext:Landroid/content/Context;

    invoke-virtual {v5}, Landroid/content/Context;->getAssets()Landroid/content/res/AssetManager;

    move-result-object v5

    const-string v6, "analyticsmigrations"

    invoke-virtual {v5, v6}, Landroid/content/res/AssetManager;->list(Ljava/lang/String;)[Ljava/lang/String;

    move-result-object v5

    invoke-static {v5}, Ljava/util/Arrays;->asList([Ljava/lang/Object;)Ljava/util/List;

    move-result-object v2

    .line 51
    .local v2, "files":Ljava/util/List;, "Ljava/util/List<Ljava/lang/String;>;"
    new-instance v5, Lcom/zuiapps/sdk/analytics/db/NaturalOrderComparator;

    invoke-direct {v5}, Lcom/zuiapps/sdk/analytics/db/NaturalOrderComparator;-><init>()V

    invoke-static {v2, v5}, Ljava/util/Collections;->sort(Ljava/util/List;Ljava/util/Comparator;)V

    .line 53
    invoke-virtual {p1}, Landroid/database/sqlite/SQLiteDatabase;->beginTransaction()V
    :try_end_1c
    .catch Ljava/lang/Throwable; {:try_start_1 .. :try_end_1c} :catch_8e

    .line 55
    :try_start_1c
    invoke-interface {v2}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v5

    :cond_20
    :goto_20
    invoke-interface {v5}, Ljava/util/Iterator;->hasNext()Z

    move-result v6

    if-eqz v6, :cond_d8

    invoke-interface {v5}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Ljava/lang/String;
    :try_end_2c
    .catchall {:try_start_1c .. :try_end_2c} :catchall_89

    .line 57
    .local v1, "file":Ljava/lang/String;
    :try_start_2c
    const-string v6, "greenDAO"

    new-instance v7, Ljava/lang/StringBuilder;

    invoke-direct {v7}, Ljava/lang/StringBuilder;-><init>()V

    const-string v8, "Upgrading schema from version "

    invoke-virtual {v7, v8}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v7

    invoke-virtual {v7, p2}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v7

    const-string v8, " to "

    invoke-virtual {v7, v8}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v7

    invoke-virtual {v7, p3}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v7

    const-string v8, ","

    invoke-virtual {v7, v8}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v7

    invoke-virtual {v7, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v7

    invoke-virtual {v7}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v7

    invoke-static {v6, v7}, Lcom/zuiapps/sdk/analytics/util/ZMLogUtil;->e(Ljava/lang/String;Ljava/lang/String;)V

    .line 58
    const-string v6, ".sql"

    const-string v7, ""

    invoke-virtual {v1, v6, v7}, Ljava/lang/String;->replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;

    move-result-object v6

    invoke-static {v6}, Ljava/lang/Integer;->valueOf(Ljava/lang/String;)Ljava/lang/Integer;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/Integer;->intValue()I

    move-result v4

    .line 60
    .local v4, "version":I
    if-le v4, p2, :cond_20

    if-gt v4, p3, :cond_20

    .line 61
    invoke-direct {p0, p1, v1}, Lcom/zuiapps/sdk/analytics/db/DatabaseOpenHelper;->executeSqlScript(Landroid/database/sqlite/SQLiteDatabase;Ljava/lang/String;)V
    :try_end_6f
    .catch Ljava/lang/Throwable; {:try_start_2c .. :try_end_6f} :catch_71
    .catchall {:try_start_2c .. :try_end_6f} :catchall_89

    .line 62
    const/4 v3, 0x1

    goto :goto_20

    .line 65
    .end local v4    # "version":I
    :catch_71
    move-exception v0

    .line 66
    .local v0, "e":Ljava/lang/Throwable;
    :try_start_72
    new-instance v6, Ljava/lang/StringBuilder;

    invoke-direct {v6}, Ljava/lang/StringBuilder;-><init>()V

    const-string v7, "Skipping invalidly named file: "

    invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v6

    invoke-static {v6, v0}, Lcom/zuiapps/sdk/analytics/util/ZMLogUtil;->e(Ljava/lang/String;Ljava/lang/Throwable;)V
    :try_end_88
    .catchall {:try_start_72 .. :try_end_88} :catchall_89

    goto :goto_20

    .line 71
    .end local v0    # "e":Ljava/lang/Throwable;
    .end local v1    # "file":Ljava/lang/String;
    :catchall_89
    move-exception v5

    :try_start_8a
    invoke-virtual {p1}, Landroid/database/sqlite/SQLiteDatabase;->endTransaction()V

    throw v5
    :try_end_8e
    .catch Ljava/lang/Throwable; {:try_start_8a .. :try_end_8e} :catch_8e

    .line 73
    .end local v2    # "files":Ljava/util/List;, "Ljava/util/List<Ljava/lang/String;>;"
    :catch_8e
    move-exception v0

    .line 74
    .restart local v0    # "e":Ljava/lang/Throwable;
    const-string v5, "greenDAO"

    new-instance v6, Ljava/lang/StringBuilder;

    invoke-direct {v6}, Ljava/lang/StringBuilder;-><init>()V

    const-string v7, "Upgrading schema from version "

    invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6, p2}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v6

    const-string v7, " to 1111"

    invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v0}, Ljava/lang/Throwable;->getMessage()Ljava/lang/String;

    move-result-object v7

    invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v6

    invoke-static {v5, v6}, Lcom/zuiapps/sdk/analytics/util/ZMLogUtil;->e(Ljava/lang/String;Ljava/lang/String;)V

    .line 76
    .end local v0    # "e":Ljava/lang/Throwable;
    :goto_b5
    const-string v5, "greenDAO"

    new-instance v6, Ljava/lang/StringBuilder;

    invoke-direct {v6}, Ljava/lang/StringBuilder;-><init>()V

    const-string v7, "Upgrading schema from version "

    invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6, p2}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v6

    const-string v7, " to 1111"

    invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6, p3}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v6

    invoke-static {v5, v6}, Lcom/zuiapps/sdk/analytics/util/ZMLogUtil;->e(Ljava/lang/String;Ljava/lang/String;)V

    .line 77
    return v3

    .line 69
    .restart local v2    # "files":Ljava/util/List;, "Ljava/util/List<Ljava/lang/String;>;"
    :cond_d8
    :try_start_d8
    invoke-virtual {p1}, Landroid/database/sqlite/SQLiteDatabase;->setTransactionSuccessful()V
    :try_end_db
    .catchall {:try_start_d8 .. :try_end_db} :catchall_89

    .line 71
    :try_start_db
    invoke-virtual {p1}, Landroid/database/sqlite/SQLiteDatabase;->endTransaction()V
    :try_end_de
    .catch Ljava/lang/Throwable; {:try_start_db .. :try_end_de} :catch_8e

    goto :goto_b5
.end method

.method private executeSqlScript(Landroid/database/sqlite/SQLiteDatabase;Ljava/lang/String;)V
    .registers 7
    .param p1, "db"    # Landroid/database/sqlite/SQLiteDatabase;
    .param p2, "file"    # Ljava/lang/String;

    .prologue
    .line 81
    const/4 v0, 0x0

    .line 83
    .local v0, "stream":Ljava/io/InputStream;
    :try_start_1
    iget-object v1, p0, Lcom/zuiapps/sdk/analytics/db/DatabaseOpenHelper;->mContext:Landroid/content/Context;

    invoke-virtual {v1}, Landroid/content/Context;->getAssets()Landroid/content/res/AssetManager;

    move-result-object v1

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V

    const-string v3, "analyticsmigrations/"

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2, p2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2}, Landroid/content/res/AssetManager;->open(Ljava/lang/String;)Ljava/io/InputStream;

    move-result-object v0

    .line 84
    invoke-direct {p0, p1, v0}, Lcom/zuiapps/sdk/analytics/db/DatabaseOpenHelper;->executeLegacySqlScript(Landroid/database/sqlite/SQLiteDatabase;Ljava/io/InputStream;)V
    :try_end_21
    .catch Ljava/lang/Throwable; {:try_start_1 .. :try_end_21} :catch_25
    .catchall {:try_start_1 .. :try_end_21} :catchall_2a

    .line 88
    invoke-static {v0}, Lcom/zuiapps/sdk/analytics/db/DatabaseOpenHelper;->closeQuietly(Ljava/io/Closeable;)V

    .line 90
    :goto_24
    return-void

    .line 85
    :catch_25
    move-exception v1

    .line 88
    invoke-static {v0}, Lcom/zuiapps/sdk/analytics/db/DatabaseOpenHelper;->closeQuietly(Ljava/io/Closeable;)V

    goto :goto_24

    :catchall_2a
    move-exception v1

    invoke-static {v0}, Lcom/zuiapps/sdk/analytics/db/DatabaseOpenHelper;->closeQuietly(Ljava/io/Closeable;)V

    throw v1
.end method


# virtual methods
.method public onCreate(Landroid/database/sqlite/SQLiteDatabase;)V
    .registers 2
    .param p1, "db"    # Landroid/database/sqlite/SQLiteDatabase;

    .prologue
    .line 38
    invoke-super {p0, p1}, Lcom/zuiapps/sdk/analytics/greendao/DaoMaster$OpenHelper;->onCreate(Landroid/database/sqlite/SQLiteDatabase;)V

    .line 39
    return-void
.end method

.method public onUpgrade(Landroid/database/sqlite/SQLiteDatabase;II)V
    .registers 7
    .param p1, "db"    # Landroid/database/sqlite/SQLiteDatabase;
    .param p2, "oldVersion"    # I
    .param p3, "newVersion"    # I

    .prologue
    .line 43
    const-string v0, "greenDAO"

    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {v1}, Ljava/lang/StringBuilder;-><init>()V

    const-string v2, "Upgrading schema from version "

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1, p2}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v1

    const-string v2, " to "

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1, p3}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-static {v0, v1}, Lcom/zuiapps/sdk/analytics/util/ZMLogUtil;->e(Ljava/lang/String;Ljava/lang/String;)V

    .line 44
    invoke-direct {p0, p1, p2, p3}, Lcom/zuiapps/sdk/analytics/db/DatabaseOpenHelper;->executeMigrations(Landroid/database/sqlite/SQLiteDatabase;II)Z

    .line 45
    return-void
.end method
